package tech.aistar.day04.homework;

import tech.aistar.util.DateUtil;

import java.util.Calendar;
import java.util.Scanner;

/**
 * 本类用来演示: 打印日历
 *
 * @author: success
 * @date: 2021/3/11 9:08 上午
 */
public class PrintCalendarDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请您输入year:>");
        int year = sc.nextInt();
        System.out.print("请您输入month:>");
        int month = sc.nextInt();

        printCalendar(year,month);
    }

    private static void printCalendar(int year, int month) {
        System.out.println("\t\t"+year+"年"+month+"月");
        System.out.println("日\t一\t二\t三\t四\t五\t六");

        //1. 获取某年某月最大天数
        int maxDays = DateUtil.getMaxDay(year,month);

        //2. 获取今天是几号 +* - 高亮显示
        //java.util.Calendar
        //1. 单个字段单个字段设置 void set(int field,int val);
        //2. 一次性设置多个字段的值 void set(int year,int month,int date);

        //Calendar cal = Calendar.getInstance();
        //int date = cal.get(Calendar.DAY_OF_MONTH);
        int date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        //3. 获取某月某月某日是周几 -> 某月某月1号是周几.
        //周日week->0
        int week = DateUtil.getWeek(year,month,1);
        //System.out.println(week);

        //定义计数器
        int count = 0;

        //打印\t - 目的是为了将1挤到后边的位置上去
        for (int i = 0; i < week; i++) {
            count++;
            System.out.print("\t");
        }

        for (int i = 1; i <= maxDays ; i++) {
            count++;

            System.out.print((i==date)?(i+"*\t"):(i+"\t"));
            if(count==7){
                System.out.println();
                count=0;
            }
        }
    }
}
